// 接口
// interface MYRARAMS{
//     age: number,
//     name: string,
// }
// class Greeter {
//     greeting: string;
//     age: number;
//     setData:(can:number)=>void
//     constructor(message: string,age?:number) {
//         this.greeting = message;
//         this.age = age as number
//         this.setData = (can) => {
//             console.log(can);
            
//         }
//     }
//     geList(params:MYRARAMS) {
//         console.log(params,123);
//     }
// }

// var greeter = new Greeter("111", 123);
// console.log(greeter.geList({
//     age: 12,
//     name:"bkpp"
// }), "123")


// 泛型应用
function myType<T, U>(can: T, can1: U): T{
    return can
}
interface MYRARAMS{
    age: number,
    name: string,
}
let thisFun = myType<number, MYRARAMS[]>(12, [{
    age: 12,
    name:"bbx"
}])
interface fanInterType{
    <T>(can:T):T
}
function fanInter<T>(can: T): T{
    return can
}
let fanInters:fanInterType=fanInter




// interface MyPerson{
//     age:string
// }
// interface MyPerson{
//     name:string
// }
// let obj: MyPerson = {
//     age: "123",
//     name:"bkpp"
// }
// interface bbx{
//     name:string
// }
// interface pcl{
//     age:number
// }
// type ALLIER = bbx | pcl
// type ALLNIERS = bbx & pcl
// let obj1: ALLNIERS = {
//     name: "123",
//     age:123
// }


interface INFO {
    readonly name: string;
    age: number;
    class: string
}

let obj1: INFO = {
    name: '111',
    age: 1,
    class: '',
}

// 随机验证码
function More(arr:number[]) {
    let num=0
     let arr1:any=arr.sort((a,b)=>a-b)
      for (let i = 0; i < arr1.length; i++) {
          if(arr1[i]==arr1[i+1]){
              num=arr[i]
          }
      }

    return num
}
console.log(More([6, 5, 6, 8, 8, 8, 8]));

// 装一个封函数unite()，传入两个或两个以上的数组，返回一个以给定的原数组排序的不包含重复值的新数组
function unite(arr: number[],arr1:number[],arr2:number[]) {
    let newArr:number[] = [...arr,...arr1,...arr2]
         let newArr1:number[] = []
         for (let i = 0; i < newArr.length; i++) {
               if(newArr1.indexOf(newArr[i])==-1){
                   newArr1.push(newArr[i])
               }
         }
         return newArr1
   }
console.log(unite([1, 3, 2], [5, 2, 1, 4], [2, 1]));
   

// 封装一个泛型类GetMax;实现找出数组中的最大值，以及最大值下标。
class GetMax<T>{
    arr:T[]
    constructor(arr:T[]){
       this.arr = arr
    }
  Max(){
      let max =0;
      let ind=0;
    this.arr.forEach((item,index)=>{
        if(typeof item=="number"&&item>max){
            max=item,
            ind=index
        }
    })
    return {
        max,ind
    }
  }
}
let getMax=new GetMax<number>([1,5,4,6,3,8,7])
 console.log(getMax.Max());
 


// 编写函数uniq(str)，返回去掉str重复项的字符串。例如：str=’defddfrt’

function unip(str:string){
    let strS:string[]=str.split("")
    let newArr:string[] =[]
for (let i = 0; i < strS.length; i++) {
      if(newArr.indexOf(strS[i])==-1){
          newArr.push(strS[i])
      }
}
return newArr.join("")


}
console.log(unip('defddfrt'));
 